package twoD.hofem;

/**
 * Linear function that maps [a, b] -> [c, d] s.t. f(a) = c and f(b) = d.
 * 
 * @author Team 5
 */

public class LinearFunctionRToR implements FunctionRToR {

	private Interval domain_;
	private double a_, b_, c_, d_, n, m;

	public LinearFunctionRToR(double a, double b, double c, double d) {
		a_ = a;
		b_ = b;
		c_ = c;
		d_ = d;
		domain_ = new Interval(a_, b_);
		m = (d_ - c_) / (b_ - a_);
		n = c_ - a_ * m;
	}

	public double valueAt(double x) {
		return x * m + n;
	}

	public double derivativeAt(double x) {
		return m;
	}

	public Interval getDomain() {
		return domain_;
	}

	public double[] getBreakpoints() {
		return null;
	}

	public int getP() {
		return 1;
	}

}
